var
  r,p:array[0..100010] of longint;

procedure makeSet(v:longint);
begin
p[v] := v;
r[v] := 0;
end;

function findSet(v:longint):longint;
begin
if v = p[v] then begin
	result := v;
	exit;
end;
p[v] := findSet(p[v]);
result := p[v];
end;

procedure unionSets(a,b:longint);

var
	t:longint;

begin
a := findSet(a);
b := findSet(b);
if a <> b then begin
	if r[a] < r[b] then begin
		t := a;
		a := b;
		b := t;
	end;
	p[b] := a;
	if r[a] = r[b] then inc(r[a]);
end;
end;